﻿package mortal.game.scene3D.player.head
{
    import com.gengine.global.*;
    import com.gengine.utils.pools.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;

    public class TalkSprite extends GSprite
    {
        public var bitMapBg:ScaleBitmap;
        protected var _talkSprite:TextRecord;
        protected var _text:String = "";
        private var _faceAuthortiy:int = 1;
        private const markX:int = 80;
        private const talkBgWidth:int = 245;
        private const talkBgHeight:int = 71;
        private const talkMinWidth:int = 130;
        private const talkMarginBg:int = 15;
        private const talkLineWidth:int = 230;
        private const talkLineHeight:int = 30;
        private const talkTextMarginY:int = 17;
        protected var _textColor:uint = 16575690;

        public function TalkSprite()
        {
            return;
        }// end function

        public function get faceAuthortiy() : int
        {
            return this._faceAuthortiy;
        }// end function

        public function set faceAuthortiy(param1:int) : void
        {
            this._faceAuthortiy = param1;
            return;
        }// end function

        public function set text(param1:String) : void
        {
            this._text = param1;
            Global.instance.callLater(this.updateText);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.mouseChildren = false;
            this.mouseEnabled = false;
            this.bitMapBg = UIFactory.bg(0, 0, this.talkBgWidth, this.talkBgHeight, this, ImagesConst.SceneTalkSelfBg);
            this.bitMapBg.x = -1 * this.markX;
            this._talkSprite = ObjectPool.getObject(TextRecord);
            this._talkSprite.init(this.talkLineWidth, this.talkLineHeight);
            this._talkSprite.defaultColor = this._textColor;
            this._talkSprite.x = -5;
            this._talkSprite.y = this.talkTextMarginY;
            this.addChild(this._talkSprite);
            return;
        }// end function

        protected function updateText() : void
        {
            if (!this._talkSprite)
            {
                return;
            }
            this._talkSprite.faceAuthortiy = this._faceAuthortiy;
            this._talkSprite.content = this._text;
            this._talkSprite.draw();
            var _loc_1:* = this._talkSprite.height;
            if (_loc_1 < this.talkLineHeight)
            {
                _loc_1 = this.talkLineHeight;
            }
            _loc_1 = _loc_1 + (this.talkBgHeight - this.talkLineHeight);
            this.bitMapBg.width = Math.max(Math.min(this.talkLineWidth, this._talkSprite.width) + 45, this.talkMinWidth);
            this.bitMapBg.height = _loc_1;
            this.bitMapBg.y = -_loc_1 + 15;
            this.bitMapBg.x = -1 * this.markX;
            this._talkSprite.y = this.bitMapBg.y + this.talkMarginBg;
            this._talkSprite.x = this.bitMapBg.x + 20;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this.bitMapBg)
            {
                this.bitMapBg.dispose(param1);
                this.bitMapBg = null;
            }
            if (this._talkSprite)
            {
                this._talkSprite.dispose(param1);
                this._talkSprite = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

    }
}
